<?php
    class AlimentacionHabitualController extends AppController {
        var $name = 'AlimentacionHabitual';
        var $uses = array('AlimentacionHabitual');
        var $helpers = array('Javascript');
        var $components = array('AdminParameters');

        function index(){

        }

        function alimentacionHabitual(){
            $this->render("alimentacionHabitual", "ajax");
        }

        function getReport($id){

            $this->data = $this->AlimentacionHabitual->find("first", array(
                "conditions" => array("AlimentacionHabitual.paciente_id" => $id)
            ));

            $this->render("get_report", "ajax");
        }

        function getListData($page=0, $limit=10, $orderColumn='id', $ascDesc='ASC'){
            $alimentacion = $this->__getListData($this->params["form"], $page, $limit, $orderColumn, $ascDesc);

            $this->set("result", $alimentacion);

            $this->render("/elements/ajax_return", "ajax");
        }

        function __getListData($params = array(), $page=0, $limit=10, $orderColumn='apellido', $ascDesc='ASC'){

            $model = "AlimentacionHabitual.";

            $fields = array(
                $model."id",
                $model."hora_desayuno", $model."desayuno",
                $model."hora_almuerzo", $model."almuerzo",
                $model."hora_merienda", $model."merienda",
                $model."hora_cena", $model."cena",
                $model."hora_colacion_1", $model."hora_colacion_2", $model."colacion"
            );

            $result = $this->AdminParameters->getListData($this->Paciente, $fields, $params, $page, $limit, $orderColumn, $ascDesc);

            return $result;

        }

        function getDetail($op, $id){

            $this->set("operation", $op);
            $this->set("editId", $id);

            $this->render("alimentacionHabitual", "ajax");

        }

        function getDetailData($id){
            $data = $this->AlimentacionHabitual->find("all", array("conditions" => array("AlimentacionHabitual.id" => $id), "recursive" => 0));

            if(sizeof($data) == 0){
                $alimentacion = array(
                    "id" => $id,
                    "paciente_id" => $id,
                    "hora_desayuno" => "",
                    "desayuno" => "",
                    "hora_almuerzo" => "",
                    "almuerzo" => "",
                    "hora_merienda" => "",
                    "merienda" => "",
                    "hora_cena" => "",
                    "cena" => "",
                    "hora_colacion_1" => "",
                    "hora_colacion_2" => "",
                    "colacion" => ""
                );


                $data[]["AlimentacionHabitual"] = $alimentacion;
            }

            $this->set("result", array("data" => $data));

            $this->render("/elements/ajax_return", "ajax");
        }

        function save(){

            if($this->AdminParameters->doSave($this->AlimentacionHabitual, $this->params["form"])){
                $this->set("result", array("result" => true));
            }else{
                $this->set("result", array("result" => false));
                $this->set("result", array("error" => "Error al guardar los datos."));
            }


            $this->render("/elements/ajax_return", "ajax");
        }

        
    }
?>